package org.wx.io.netty.chart.client;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @description: 客户端监听
 * @author: wangxun
 * @createDate: 2021/2/19
 * @version: 1.0
 */
@Slf4j
public class ClientListener implements ChannelFutureListener {
    private NettyChartClient client = new NettyChartClient();

    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
        if(future.isSuccess()){
            log.info("进入聊天室成功..");
        }else{
            future.channel().eventLoop().schedule(new Runnable() {
                @Override
                public void run() {
                    log.info("断线重新连接...");
                    client.doConnect("127.0.0.1",9000);
                }
            }, 10, TimeUnit.SECONDS);
        }
    }
}
